﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LoginLockDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            //添加测试用户
            //Tset();
            //1.用用户名和密码查询是否存在对应的Userinfo的记录，判断是否被锁定，存在即登陆成功

            //先查询是否存在此用户
            var connStr = ConfigurationManager.AppSettings["connStr"];
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = @"select * from userinfo where username='" + txtUserName.Text + "'";

                    UserInfo user = new UserInfo();
                    using (SqlDataReader rdr = cmd.ExecuteReader())
                    {
                        //把查询出来的数据赋值user对象
                    }

                }
            }
        }


        private void Tset()
        {
            UserInfo user = new UserInfo
            {
                UserName = "Gigi",
                PassWord = Encryption.GetEncryptString("123"),
            };

            //连接串
            var connStr = ConfigurationManager.AppSettings["connStr"];

            using (SqlConnection conn = new SqlConnection(connStr))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = string.Format("insert UserInfo values('{0}','{1}','{2}',{3},{4},null)",
                        user.UserID, user.UserName, user.PassWord,Convert.ToInt32(user.IsLocked),user.ErrorTimes);
                    cmd.ExecuteNonQuery();
                }
            }
        }
    }
}
